const initialState = {
  count: 100,
}

const countModel = {
  namespace: "count",
  state: initialState,
  reducers: {
    setState(state = initialState, { payload }) {
      return {
        ...state,
        ...payload,
      }
    },
  },
  effects: {
    *add(action, { put, select }) {
      console.log("action", action)
      const { count } = yield select(state => state.count)
      console.log(count)
      yield put({
        type: "setState",
        payload: {
          count: count + action.payload.count,
        },
      })
    },
    *asyncAdd(action, { put, select }) {
      yield new Promise(resolve => {
        setTimeout(() => {
          resolve()
        }, 2000)
      })
      console.log("action", action)
      const { count } = yield select(state => state.count)
      console.log(count)
      yield put({
        type: "setState",
        payload: {
          count: count + action.payload.count,
        },
      })
    },
  },
  subscriptions: {
    
  },
}

export default countModel
